package wpspider.client.view.component.toolbar;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

public class SearchComboBox extends JComboBox {
	public static final int ELEMENT_MAX = 20;

	DefaultComboBoxModel _model;

	public SearchComboBox() {
		_model = (DefaultComboBoxModel) this.getModel();
	}

	public boolean addItem(String word) {
		if (word == null || word.length() == 0) {
			return false;
		} else {
			this.setVisible(false);
			_model = (DefaultComboBoxModel) this.getModel();
			_model.removeElement(word);
			_model.insertElementAt(word, 0);
			if (_model.getSize() > ELEMENT_MAX) {
				_model.removeElementAt(ELEMENT_MAX);
			}
			this.setSelectedIndex(0);
			this.setVisible(true);
			return true;
		}
	}
}
